1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 import java.lang.management.*;
35 import javax.management.*;
36 import javax.management.openmbean.*;
37
38 public class MBeanOperationInfoTest {
39 private static final String[][] returnTypes = {
40 { "dumpAllThreads(boolean,boolean)", "[Ljavax.management.openmbean.CompositeData;" },
41 { "findDeadlockedThreads()", "[J" },
42 { "findMonitorDeadlockedThreads()", "[J" },
43 { "getThreadInfo(long)","javax.management.openmbean.CompositeData"},
44 { "getThreadInfo(long,int)","javax.management.openmbean.CompositeData"},
45 { "getThreadInfo([J)","[Ljavax.management.openmbean.CompositeData;"},
46 { "getThreadInfo([J,int)","[Ljavax.management.openmbean.CompositeData;"},
47 { "getThreadInfo([J,boolean,boolean)","[Ljavax.management.openmbean.CompositeData;"},
48 { "getThreadCpuTime(long)","long"},
49 { "getThreadUserTime(long)","long"},
50 { "resetPeakThreadCount()","void"},
51 };
52 public static void main(String[] args) throws Exception {
53 int error = 0;
54 int tested = 0;
55 MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
56 ObjectName on = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
57 MBeanInfo mbi = mbs.getMBeanInfo(on);
58 MBeanOperationInfo[] ops = mbi.getOperations();
59 for (MBeanOperationInfo op : ops) {
60 String name = op.getName();
61 String rt = op.getReturnType();
62 StringBuilder sb = new StringBuilder();
63 sb.append(name + "(");
64 for (MBeanParameterInfo param : op.getSignature()) {
65 sb.append(param.getType() + ",");
66 }
67 int comma = sb.lastIndexOf(",");
68 if (comma == -1) {
69 sb.append(")");
70 } else {
71 sb.replace(comma, comma + 1, ")");
72 }
73 System.out.println("\nNAME = " + sb.toString() + "\nRETURN TYPE = " + rt);
74 for (String[] rts : returnTypes) {
75 if (sb.toString().equals(rts[0])) {
76 if (rt.equals(rts[1])) {
77 System.out.println("OK");
78 tested++;
79 } else {
80 System.out.println("KO: EXPECTED RETURN TYPE = " + rts[1]);
81 error++;
82 }
83 }
84 }
85 }
86 if (error > 0) {
87 System.out.println("\nTEST FAILED");
88 throw new Exception("TEST FAILED: " + error + " wrong return types");
89 } else if (tested != returnTypes.length &&
90 !System.getProperty("java.specification.version").equals("1.5")) {
91 System.out.println("\nTEST FAILED");
92 throw new Exception("TEST FAILED: " + tested + " cases tested, " +
93 returnTypes.length + " expected");
94 } else {
95 System.out.println("\nTEST PASSED");
96 }
97 }
98 }